import imp
from urllib import request
from django.shortcuts import render

# Create your views here.
from rest_framework import viewsets
from rest_framework.decorators import action
from rest_framework.response import Response
from django_filters import rest_framework as filters

from .models import  *
from .serializer import *

from rest_framework.pagination import PageNumberPagination
#分页

class StandardPageNumberPagination(PageNumberPagination):
    page_size = 2
    page_query_param = 'page'
    page_size_query_param = 'page_size'
    max_page_size = 10

class HtmlConfigViewSet(viewsets.ModelViewSet):
    queryset = HtmlConfig.objects.all()
    serializer_class = HtmlConfigSerializer
    #过滤
    filter_fields = ('id', 'htmlName')
    #排序
    ordering_fields = ('id')

    #自定义方法
    @action(methods=['get','post','put','delete'], detail=False, url_path='exec_task')
    def exec_task(self,request, *args, **kwargs):
        print (request.method,args,kwargs,request.data)
        dd = {"w":"ww","ee":"ttt"}
        return Response(dd)

